//
//  TranditionalScrollCell.m
//  PersonalHospital
//
//  Created by qianfeng on 15/12/12.
//  Copyright (c) 2015年 QianFeng. All rights reserved.
//

#import "TranditionalScrollCell.h"


@interface TranditionalScrollCell ()<UIScrollViewDelegate>

@property(nonatomic,strong)UIScrollView * scrollView;

@end

@implementation TranditionalScrollCell

-(UIScrollView *)scrollView{
    if (_scrollView==nil) {
        _scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, KScreen_Size.width, KTranditional_Scroll_Cell)];
    }
    return _scrollView;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addUI];
    }
    return self;
}

-(void)addUI{
    self.scrollView.delegate=self;
    self.scrollView.pagingEnabled=YES;
    self.scrollView.showsHorizontalScrollIndicator=NO;
    [self.contentView addSubview:self.scrollView];
}

-(void)setScrollIndex:(NSInteger)scrollIndex{
    _scrollIndex=scrollIndex;
    [self.scrollView setContentOffset:CGPointMake(self.scrollView.frame.size.width*self.scrollIndex, 0)];
}


-(void)setArray:(NSMutableArray *)array{
    _array=array;
    self.scrollView.contentSize=CGSizeMake(KScreen_Size.width*(array.count), self.scrollView.frame.size.height);
    
    for (int i=0; i<array.count; i++) {
        [array[i] view].frame=CGRectMake(self.scrollView.frame.size.width*i, 0, self.scrollView.frame.size.width, self.scrollView.frame.size.height);        [self.scrollView addSubview:[array[i] view]];
    }
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGFloat index=self.scrollView.contentOffset.x/self.scrollView.frame.size.width;
    _scrollIndex=index;
    if (_scorll) {
        self.scorll(_scrollIndex);
    }
}

@end
